package com.business.web.spring;


import java.util.List;
import org.apache.log4j.Logger;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//import com.workflow.WorkFlowUtils;
import com.common.db.JsonVO;
import com.common.db.Pg;
import com.common.utils.BeanUtils;
import com.business.domain.T_img;
//import com.business.mapper.T_imgMapper;
import com.business.service.T_imgService;

@Controller
@RequestMapping("/t_img")

public class T_imgController
{
	private static Logger log = Logger.getLogger(T_imgController.class.getName());

	@Resource
    private T_imgService t_imgService;

	//@Autowired
	//private WorkFlowUtils workFlowUtils;

	//@Resource
	//private T_imgMapper mapper;
	//private int id;
	//private int[] ids;
	private Pg pg;

	/**
	 * 1、获取 T_img信息列表，并且在列表页面展示
	 * @param request
	 * @return Pg，json格式
	 */
	@RequestMapping("/getAllT_img")
	@ResponseBody
	public Pg getAllT_img(HttpServletRequest request){
        int pageSize = 10;
        int startIndex = 0;
        T_img t_img = new T_img();
        try{
	        if(request.getParameter("pageSize")!=null){
	        	pageSize = BeanUtils.stringToInt("pageSizeFlag", request.getParameter("pageSize"));
	        }
	        if(request.getParameter("startIndex")!=null){
	            startIndex = BeanUtils.stringToInt("startIndexFlag", request.getParameter("startIndex"));
	        }
	        if(request.getParameter("process_code")!=null){ //取得动作流 流程英文名称，后台查询数据关联使用
	        	t_img.setProcess_code(request.getParameter("process_code"));
	        }
			if(request.getParameter("img_path")!=null&&!"".equals(request.getParameter("img_path"))){
	        	t_img.setImg_path(request.getParameter("img_path"));
	        }
			if(request.getParameter("ext1")!=null&&!"".equals(request.getParameter("ext1"))){
	        	t_img.setExt1(request.getParameter("ext1"));
	        }
			if(request.getParameter("ext2")!=null&&!"".equals(request.getParameter("ext2"))){
	        	t_img.setExt2(request.getParameter("ext2"));
	        }
			if(request.getParameter("ext3")!=null&&!"".equals(request.getParameter("ext3"))){
	        	t_img.setExt3(request.getParameter("ext3"));
	        }
			if(request.getParameter("customer_id")!=null&&!"".equals(request.getParameter("customer_id"))){
	        	t_img.setCustomer_id(request.getParameter("customer_id"));
	        }
			if(request.getParameter("status")!=null&&!"".equals(request.getParameter("status"))){
	        	t_img.setStatus(request.getParameter("status"));
	        }
			if(request.getParameter("img_path2")!=null&&!"".equals(request.getParameter("img_path2"))){
	        	t_img.setImg_path2(request.getParameter("img_path2"));
	        }
			if(request.getParameter("company_name")!=null&&!"".equals(request.getParameter("company_name"))){
	        	t_img.setCompany_name(request.getParameter("company_name"));
	        }
			if(request.getParameter("creater")!=null&&!"".equals(request.getParameter("creater"))){
	        	t_img.setCreater(request.getParameter("creater"));
	        }
			if(request.getParameter("creattime")!=null&&!"".equals(request.getParameter("creattime"))){
	        	t_img.setCreattime(request.getParameter("creattime"));
	        }
			if(request.getParameter("updater")!=null&&!"".equals(request.getParameter("updater"))){
	        	t_img.setUpdater(request.getParameter("updater"));
	        }
			if(request.getParameter("updatetime")!=null&&!"".equals(request.getParameter("updatetime"))){
	        	t_img.setUpdatetime(request.getParameter("updatetime"));
	        }
			if(request.getParameter("product_name1")!=null&&!"".equals(request.getParameter("product_name1"))){
	        	t_img.setProduct_name1(request.getParameter("product_name1"));
	        }
			if(request.getParameter("product_name2")!=null&&!"".equals(request.getParameter("product_name2"))){
	        	t_img.setProduct_name2(request.getParameter("product_name2"));
	        }
			if(request.getParameter("product_name3")!=null&&!"".equals(request.getParameter("product_name3"))){
	        	t_img.setProduct_name3(request.getParameter("product_name3"));
	        }
			if(request.getParameter("customer_name")!=null&&!"".equals(request.getParameter("customer_name"))){
	        	t_img.setCustomer_name(request.getParameter("customer_name"));
	        }
			if(request.getParameter("customer_address")!=null&&!"".equals(request.getParameter("customer_address"))){
	        	t_img.setCustomer_address(request.getParameter("customer_address"));
	        }
      	    if(request.getParameter("img_id")!=null&&!"".equals(request.getParameter("img_id"))){
	        	t_img.setImg_id(new Integer(request.getParameter("img_id")));
	        }
      	    if(request.getParameter("goods_id")!=null&&!"".equals(request.getParameter("goods_id"))){
	        	t_img.setGoods_id(new Integer(request.getParameter("goods_id")));
	        }
	        if(request.getParameter("startdate")!=null&&!"".equals(request.getParameter("startdate"))){
	        	t_img.setStartdate(request.getParameter("startdate"));
	        }
	        if(request.getParameter("enddate")!=null&&!"".equals(request.getParameter("enddate"))){
	        	t_img.setEnddate(request.getParameter("enddate"));
	        }
	        t_img.setStartNo( startIndex );
	        t_img.setPageSize( pageSize );
	        t_img.setEndNo( pageSize );
	    	List<T_img> findAll = t_imgService.findAll(t_img);
	        int totalCount = t_imgService.findCountAll(t_img);
	       	pg = new Pg(findAll, totalCount, pageSize, startIndex);
	       	request.setAttribute("t_imgList", findAll);
		    request.setAttribute("pg", pg);
	    } catch (Exception e) {
			e.printStackTrace();
			log.error("------query t_imgList error:"+e);
		}

		return pg;
	}

	/**
	 * 2、新增保存  T_img信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param user
	 * @param request
	 * @return
	 */
	@RequestMapping("/saveT_img")
	@ResponseBody
	public JsonVO saveT_img(T_img t_img, HttpServletRequest request,HttpServletResponse response){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊需求，需要将json对象值转成java实体对象属性值
		if(t_imgService.save(t_img)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 3、修改T_img信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_img
	 * @param request
	 * @return JsonVO
	 */
	@RequestMapping("/updateT_img")
	@ResponseBody
	public JsonVO updateT_img(T_img t_img, HttpServletRequest request){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊值需要处理，在此处手工转换
		//T_img t_imgTemp = t_imgService.findById(t_img);
		//t_imgTemp.setXXX(t_img.getXXX());
		//if(t_imgService.update(t_imgTemp)){

		if(t_imgService.update(t_img)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 4、根据id查询T_img单个信息并显示在修改页面
	 * @param id
	 * @param request
	 * @return T_img json格式字符串
	 */
	@RequestMapping("/getT_img")
	@ResponseBody
	public T_img getT_img(Integer id,HttpServletRequest request){
		T_img t_img = new T_img();
		t_img.setImg_id(id);
		return t_imgService.findById(t_img);
	}

	/**
	 * 5、删除T_img根据id
	 * @param id
	 * @param request
	 * @param response
	 * return JsonVO ：json格式字符串
	 */
	@RequestMapping("/delT_img")
	@ResponseBody
	public JsonVO delT_img(Integer id,HttpServletRequest request,HttpServletResponse response){
        JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);

		T_img t_img = new T_img();
		t_img.setImg_id(id);

		if(t_imgService.delete(t_img)>0){
			vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 6、跳转到t_img/toT_imgList查询所有数据页面
	 *  return /WEB-INF/views/business/t_img/t_imgList.jsp
	 */
    @RequestMapping(value = "/toT_imgList")
    public String toT_imgList() {
    	log.debug("------跳转到/WEB-INF/views/business/t_img/t_imgList.jsp------");
        return "business/t_img/t_imgList";
    }

	/**
	 * 7、新增、修改、详情页面t_img/toT_imgCurd跳转
     * business/t_img/T_imgCurd.jsp
	 */
    @RequestMapping(value = "/toT_imgCurd")
    public String toT_imgCurd() {
    	log.debug("------跳转到/WEB-INF/views/business/t_img/t_imgCurd.jsp------");
        return "business/t_img/t_imgCurd";
    }

    /**
	 * 8、批量删除T_img根据主键id
	 * 是否要实现批量删除，待考虑，基本上用途不大
	 * @param id
	 * @param request
	 * @param response
	@RequestMapping("/delT_imgBatch")
	public String delT_imgBatch(HttpServletRequest request,HttpServletResponse response){
		String[] ids = request.getParameterValues("ids");
		System.out.println("------ids="+ids);
		T_img t_img = new T_img();
		int j=0;
		for(int i =0;i< ids.length;i++){
			j++;
			log.error("------ids[i]="+ids[i]);
			t_img.setImg_id(new Integer(ids[i]).intValue());
			t_imgService.delete(t_img);
		}
		if(j==ids.length){
			log.debug("------t_img批量删除成功！------");
		}else{
			log.error("------t_img批量删除部分成功！部分失败！------");
		}

		return "redirect:/t_img/getAllT_img";
	}
*/



}









